#ifndef RTC_DRIVER_H
#define RTC_DRIVER_H

#include "gd32f10x.h"
#include "gd32f10x_rtc.h"
#include "time.h"
#include "stdbool.h"

typedef struct
{
    uint16_t Year;
    uint8_t Month;
    uint8_t Day;
    uint8_t Week;
    uint8_t Hour;
    uint8_t Minute;
    uint8_t Second;
} _DateTime;


typedef struct
{
    uint8_t WeekDay; /*!< Specifies the RTC Date WeekDay (not necessary for HAL_RTC_SetDate).
                        This parameter can be a value of @ref RTC_WeekDay_Definitions */

    uint8_t Month; /*!< Specifies the RTC Date Month (in BCD format).
                      This parameter can be a value of @ref RTC_Month_Date_Definitions */

    uint8_t Date; /*!< Specifies the RTC Date.
                     This parameter must be a number between Min_Data = 1 and Max_Data = 31 */

    uint8_t Year; /*!< Specifies the RTC Date Year.
                     This parameter must be a number between Min_Data = 0 and Max_Data = 99 */

} RTC_DateTypeDef;

typedef struct
{
    uint8_t Hours; /*!< Specifies the RTC Time Hour.
                      This parameter must be a number between Min_Data = 0 and Max_Data = 23 */

    uint8_t Minutes; /*!< Specifies the RTC Time Minutes.
                        This parameter must be a number between Min_Data = 0 and Max_Data = 59 */

    uint8_t Seconds; /*!< Specifies the RTC Time Seconds.
                        This parameter must be a number between Min_Data = 0 and Max_Data = 59 */

} RTC_TimeTypeDef;

bool rtc_init(void);
void set_time(uint16_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute, uint8_t second);
void get_time(uint16_t* year, uint8_t*month, uint8_t*day, uint8_t*hour, uint8_t*minute, uint8_t*second);
uint32_t get_timestamp(void);
void RTC_IRQHandler(void);
void unixToTime(uint32_t UnixNum, _DateTime* rt_time);
void rtc_int_second_disable(void);
bool is_need_to_report_config(void);

#endif